const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    port: 8081,
    open: true,
    onBeforeSetupMiddleware(devServer) {
      devServer.app.get('/api/tmp', (req, res) => {
        res.json(require('./data/tmp'))
      })
      devServer.app.get('/api/nowplaying', (req, res) => {
        res.json(require('./data/nowplaying.json'))
      })
      devServer.app.get('/api/upcoming', (req, res) => {
        res.json(require('./data/upcoming.json'))
      })
      devServer.app.get('/api/MovieMsg', (req, res) => {
        res.json(require('./data/MovieMsg/' + req.query.name + '.json'))
      })
      devServer.app.get('/api/img', (req, res) => {
        // 发送图片
        res.sendFile(require('path').resolve('./data/img/' + req.query.name + '.webp'))
        // console.log(req.query.name)
      })
      devServer.app.get('/api/movie/in_theaters', (req, res) => {
        res.json(require('./data/Home/data.json'))
      })
    }
  }
})
